<template>
  <el-dialog title="编辑招聘信息" width="50%" :visible.sync="dialogVisible" :before-close="handleClose">
	<el-form  ref="form" :model="form" label-width="120px" :rules="rules">	
	
	  <el-form-item label="信息编号" prop="id">
		<el-input v-model="form.id" :disabled="true" style="width: 60%;"></el-input>
	  </el-form-item>

	  <el-form-item label="招聘部门" prop="name">
	  	<el-select v-model="form.name" placeholder="...请选择">
	  	  <el-option v-for="dept in form.deptName" :label="dept" :value="dept" :key="dept"></el-option>
	  	</el-select>
	  </el-form-item>
	  
	  <el-form-item label="学历背景" prop="edaBg">
	    <el-radio-group v-model="form.edaBg">
	      <el-radio v-for="edu in eduBgs" :label="edu" :value="edu" :key="edu">{{edu}}</el-radio>
	    </el-radio-group>
	  </el-form-item>
	  
	  <el-form-item label="招聘需求" prop="campusRecruitment">
	  	<el-input type="textarea" v-model="form.campusRecruitment" clearable style="width: 80%;"></el-input>
	  </el-form-item>
	  
	  <el-form-item label="需求人数" prop="nums">
	  	<el-input v-model="form.nums" clearable style="width: 80%;"></el-input>
	  </el-form-item>
	  
	  
	  <el-form-item>
	  	<el-button type="primary" @click="saveRecruit()">保 存</el-button>
	  	<el-button @click="reset()">重 置</el-button>
	  </el-form-item>
	</el-form>
  </el-dialog>
</template>

<script>
  export default {
    name: 'updateDialog',
    data() {
      return {
		form: {
			id:'',
			name: '',
			campusRecruitment: '',
			edaBg: '',
			nums:'',
			deptName:[],
		},
        //表单验证规则
		eduBgs:['大专及以下','本科','硕士','博士及以上'],
        rules: {
        	name: [
        	  {required: true,message: '请选择一个部门',trigger: 'change'}
        	],
        	nums: [
        		{required: true,message: '请输入岗位HC',trigger: 'blur'},
        		{min: 1,max: 4,message: '长度在 1 到 4 个字符',trigger: 'blur'}
        	],
        	campusRecruitment: [
        		{required: true,message: '内容不能为空',trigger: 'blur'}
        	],
        },
        dialogVisible: false,
        loading: false,
      };
    },
    methods: {
      //关闭页面前的回调
      handleClose(done) {
        if (this.loading) {
          return;
        }
        this.$confirm('确定关闭将不会保存数据？')
          .then(() => {
            this.loading = true;
            this.timer = setTimeout(() => {
              done();
              this.loading = false;
            }, 100);
            this.reset();
          })
          .catch(() => {});
      },
      //关闭会话前重置表单
      reset() {
        this.$refs.form.resetFields();
        this.getRecruitByid(this.form.id)
      },
      getRecruitByid(id) {
        this.form.id = id
		var that = this
        this.$http.get("/recruitMeg/getRecruitInfo?id=" + id).then(function(res) {
          that.form.id = res.data.recruitInfo.id;
          that.form.name = res.data.recruitInfo.name;
          that.form.campusRecruitment = res.data.recruitInfo.campusRecruitment;
          that.form.edaBg = res.data.recruitInfo.edaBg;
          that.form.nums = res.data.recruitInfo.nums;
          that.form.deptName = res.data.recruitInfo.deptName;
		  
        })
      },
      //保存修改后的数据
      saveRecruit() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            var that = this
            this.$http.post("/recruitMeg/updateRecruit/", this.form).then(function(res) {
              if (res.data.code == 200) {
                that.$message({
                  showClose: true,
                  message: "保存成功",
                  type: 'success'
                });
                //整个页面进行刷新
                window.location.reload();
              }else {
                that.$message({
                  showClose: true,
                  message:"保存失败",
                  type: 'error'
                });
              }
            })
          } else {
            return false;
          }
        })
      }
    }
  };

</script>

<style>

</style>
